Skip to content

fix(auth): restrict signup write-surface to client-settable fields (mass assignment)#3867

Merged
PierreBrisorgueil merged 4 commits into
masterfrom
fix/signup-mass-assignment
Jun 15, 2026
Merged

fix(auth): restrict signup write-surface to client-settable fields (mass assignment)#3867
PierreBrisorgueil merged 4 commits into
masterfrom
fix/signup-mass-assignment

Conversation

@PierreBrisorgueil

Copy link
Copy Markdown
Contributor

Summary

  • What changed: Added a strict SignupUser Joi schema that exposes only client-settable fields (name, firstName, lastName, email, password). The signup controller now strips roles and forces emailVerified:false, and explicitly deletes all server-owned fields (currentOrganization, providerData, token, lock) before passing data to the service.
  • Why: The public signup endpoint previously validated the payload against the full User schema, leaving emailVerified, providerData, token, and lock fields client-writable. Setting emailVerified:true on signup defeats the OAuth-annexation guard (a HIGH finding in the security audit). Both the schema restriction and the controller strip are independent defence-in-depth layers, each covered by failing-first tests.
  • Related issues: Closes 🔒 Mass assignment on signup (emailVerified/providerData client-settable) #3850. Part of the security audit epic 🎯 Security audit hardening — Node + Vue (2026-06 audit) #3848.

Scope

  • Module(s) impacted: modules/auth (controller, routes, tests), modules/users/models (new SignupUser schema export)
  • Cross-module impact: none — the new schema is self-contained in users.schema.js and consumed only by the auth signup path
  • Risk level: low — strictly reduces the accepted write-surface; no behaviour change for well-formed requests

Validation

  • npm run lint
  • npm test
  • Manual checks done (if applicable)

Guardrails check

  • No secrets or credentials introduced (.env*, secrets/**, keys, tokens)
  • No risky rename/move of core stack paths
  • Changes remain merge-friendly for downstream projects
  • Tests added or updated when behavior changed

Notes for reviewers

  • Security considerations: Two independent layers — (1) Joi .strict() schema at the route level rejects unknown fields before they reach the controller; (2) controller hard-deletes server-owned fields and forces roles / emailVerified to safe defaults. Either layer alone closes the mass-assignment vector.
  • Mergeability considerations: Additive only; downstream projects gain the new SignupUser schema export without any breaking change to existing exports.
  • Follow-up tasks: S1 (OAuth-takeover), S3 (org self-join), S4 (NODE_ENV prod env-gate) are tracked under epic 🎯 Security audit hardening — Node + Vue (2026-06 audit) #3848.

@PierreBrisorgueil PierreBrisorgueil added the Fix A bug fix label Jun 14, 2026
@PierreBrisorgueil PierreBrisorgueil self-assigned this Jun 14, 2026
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@PierreBrisorgueil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 34 minutes and 33 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 94b707fd-ab45-4544-8904-7efd3c7ce596

📥 Commits

Reviewing files that changed from the base of the PR and between c31a5f0 and 8ac640b.

📒 Files selected for processing (5)
  • modules/auth/controllers/auth.controller.js
  • modules/auth/routes/auth.routes.js
  • modules/auth/tests/auth.integration.tests.js
  • modules/auth/tests/auth.silent.catch.unit.tests.js
  • modules/users/models/users.schema.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/signup-mass-assignment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.48%. Comparing base (c31a5f0) to head (8ac640b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3867   +/-   ##
=======================================
  Coverage   92.48%   92.48%           
=======================================
  Files         165      165           
  Lines        5400     5403    +3     
  Branches     1735     1735           
=======================================
+ Hits         4994     4997    +3     
  Misses        326      326           
  Partials       80       80           
Flag Coverage Δ
integration 60.20% <100.00%> (+0.02%) ⬆️
unit 73.44% <80.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c31a5f0...8ac640b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… invite path

The P8a integration test (and real invite-flow clients) sends referredBy in the
signup body to verify the server ignores it. The .strict() SignupUser schema
rejected it with 422 instead of stripping it. Fix: accept referredBy as optional
in SignupUser (avoids the 422) and unconditionally delete it in the controller
serverOwned list — the server always sets it via the invite finalize seam.
Security invariant preserved: a client can never self-assign a referrer.
@PierreBrisorgueil PierreBrisorgueil marked this pull request as ready for review June 14, 2026 20:07
Copilot AI review requested due to automatic review settings June 14, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the public /api/auth/signup path against mass-assignment by narrowing the validated request schema to a dedicated strict signup write-surface and adding controller-side scrubbing as defense in depth.

Changes:

  • Added a new strict SignupUser Zod schema exposing only client-settable signup fields and exported it from users.schema.js.
  • Updated the signup route to validate against UsersSchema.SignupUser instead of the full UsersSchema.User.
  • Added/updated tests to ensure server-owned fields are rejected at the route layer and stripped before UserService.create.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
modules/users/models/users.schema.js Adds and exports SignupUser strict Zod schema intended for public signup validation.
modules/auth/routes/auth.routes.js Switches /api/auth/signup validation from full User schema to SignupUser.
modules/auth/controllers/auth.controller.js Adds controller-side scrubbing/forcing of roles and emailVerified (defense in depth).
modules/auth/tests/auth.silent.catch.unit.tests.js Adds a unit test asserting controller-side stripping before UserService.create.
modules/auth/tests/auth.integration.tests.js Adds an integration test asserting strict schema rejects server-owned fields (422) and prevents persistence.

Comment on lines +83 to +85
* `SignupUser` exposes ONLY the fields a public signup may legitimately set — the same
* safe surface encoded by `config.whitelists.users.default` / `.update` — and is
* `.strict()`, so any unknown / server-owned key is REJECTED (422) instead of silently
Comment on lines +129 to +142
const safeBody = { ...req.body, roles: ['user'], emailVerified: false };
for (const serverOwned of [
'providerData',
'additionalProvidersData',
'resetPasswordToken',
'resetPasswordExpires',
'emailVerificationToken',
'emailVerificationExpires',
'failedLoginAttempts',
'lockUntil',
'lastLoginAt',
'currentOrganization',
'referredBy',
]) delete safeBody[serverOwned];
@PierreBrisorgueil PierreBrisorgueil merged commit 9f10307 into master Jun 15, 2026
8 checks passed
@PierreBrisorgueil PierreBrisorgueil deleted the fix/signup-mass-assignment branch June 15, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🔒 Mass assignment on signup (emailVerified/providerData client-settable)

2 participants